package com.cat.dataStructure;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 *   @description https://leetcode.cn/problems/group-anagrams/?envType=study-plan-v2&envId=top-100-liked
 *   @author 曲大人的喵
 *   @create 2025/9/24 22:20
 *   @since JDK17
 */

public class Solution77 {
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> ans = new ArrayList<>();
        HashMap<String, List<String>> map = new HashMap<>();
        for (var s : strs) {
            char[] array = s.toCharArray();
            Arrays.sort(array);
            map.computeIfAbsent(new String(array), k -> new ArrayList<>()).add(s);
        }
        for (var list : map.values()) {
            ans.add(list);
        }
        return ans;
    }
}
